package com.sys.controller;

import com.sys.bean.Admin;
import com.sys.bean.RespBean;
import com.sys.service.AdminService;
import com.sys.utils.JwtUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;
@CrossOrigin
/*
* 获取已登录用户的信息并返回
* */
@RestController
@RequestMapping("/admin/info")
public class InfoController {
    @Autowired
    private AdminService adminService;

    @GetMapping("/top5")
    public RespBean selectTop5ParkNameAndCount()  {
        List<Map<String, Object>> mapList = adminService.selectTop5ParkNameAndCount();
        return RespBean.ok("", mapList);
    }

    @GetMapping("/adminInfo")
    public RespBean getLoginInfo(HttpServletRequest request) {
        //获取jwt
        String token = request.getHeader("token");
        //解析jwt
        Map<String, Object> map = JwtUtil.parseJwtToMap(token);
        Integer id = (Integer) map.get("id");
        //根据ID查询用户信息
        Admin admin = adminService.selectByid(id);
        //返回
        return RespBean.ok("", admin);
    }

}
